import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

export class Todo {
  name: string;
  monthId: string;
  month: string;
  year: string;
  balance: string;
  pay: string;
  income: string;
  monthPayList: []
}
export interface AppState {
  todos: Todo[];
}
@Component({
  selector: 'home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  headerTitle = '收支';
  currentMonth;
  currentAccount;
  monthList = [];
  accountList = [];
  data;
  currentValue: any = {};
  constructor(private httpClient: HttpClient) {
  }
  ngOnInit() {
    this.httpClient.get('/assets/data/data.json').subscribe((res) => {
      this.data = res;
      console.log(this.data);
      this.monthList = this.data.monthList;
      this.accountList = this.data.accountList;
      this.currentMonth = this.monthList[0];
      this.currentAccount = this.accountList[0];
      this.currentValue = this.data.payList.find((item) => {
        return item.monthId === this.currentMonth.monthId;
      })
      const a = this.currentValue.monthPayList.filter((item) => {
        return item.date !== '20200103';
      })
      console.log(a);
    })
  }

  getMonth(event) {
    console.log(event);
    this.currentValue = this.data.payList.find((item) => {
      return item.monthId === event;
    })
  }
  getAccount(event) {
    console.log(event);
  }
}
